// index.js


import { getStatusBarAndMenuButtonInfo } from '../../utils/util.js'
const app = getApp()
let currentTabStorage = wx.getStorageSync('currentTab')
if (currentTabStorage === undefined || currentTabStorage === null || currentTabStorage === '') {
  currentTabStorage = 1
}
console.log('currentTabStorage:',currentTabStorage)
Page({
  data: {
    currentTab: currentTabStorage ,
    statusBarHeight: 0,
    menuBarHeight: 44,
  },
  
  onLoad(options) {
    console.log('index onLoad options:',options)
    // 获取视频列表
    this.initTabStyle()
    // let currentTabStorage = wx.getStorageSync('currentTab')
    // if (currentTabStorage !== undefined || currentTabStorage !== null) {
    //   this.setData({
    //     currentTab: currentTabStorage
    //   })
    // }
    
  },

  

  initTabStyle(){
    const { statusBarHeight, menuBarHeight,menuButtonHeight,menuButtonGutter } = getStatusBarAndMenuButtonInfo()
    this.setData({
      statusBarHeight,
      menuBarHeight,
      menuButtonGutter,
      menuButtonHeight
    })
  },
  tabsClick (event) {
    // console.log('tabsClick:',event)
    let index = event.detail.index
    if(index===0){
      let childCom = this.selectComponent('#videoSwiper')
      if (childCom) {
        childCom.stopAllAudioAndVideo()
      }
    }else if(index===1){
      let hadInVideoSwiper = app.globalData.hadInVideoSwiper
      console.log('hadInVideoSwiper:',hadInVideoSwiper)
      if(!hadInVideoSwiper){
        let childCom = this.selectComponent('#videoSwiper')
        if (childCom) {
          childCom.initVideoAndAudioAni()
        }
        app.globalData.hadInVideoSwiper = true
      }
      
    }
    // wx.showToast({
    //   title: `点击标签 ${event.detail.name}`,
    //   icon: 'none',
    // });
    // var tabTitle = event.detail.title
    // if (tabTitle == '收藏') {
    //   wx.setNavigationBarColor({
    //     backgroundColor: '#ffffff',
    //     frontColor: '#000000',
    //   })
    // } else {
    //   wx.setNavigationBarColor({
    //     backgroundColor: '#000000',
    //     frontColor: '#ffffff',
    //   })
    // }
  },
  tabChange (event) {
    // console.log('tabChange:',event)
    this.setData({
      currentTab: event.detail.index
    })
    wx.setStorageSync('currentTab', event.detail.index)
    
    
  },
  beforeTabChange (event) {
    const { callback, title } = event.detail
    callback(true)
  },
  getShareData(){
    let activeVideo = app.globalData.activeVideo
    console.log('getShareData activeVideo:',activeVideo)
    if(activeVideo){
      let url = '/pages/index/index?shareMediaId='+activeVideo.mediaId
      if(app.globalData.isInEvaluation){
        url += '&quickShowQuestionnaire=1'
      }
      return {
        title: app.globalData.curQuestionnaireTitle || activeVideo.mediaTitle,
        path: url,
        imageUrl: activeVideo.mediaFactUrl
      }
    }else{
      return {
        title: app.globalData.curQuestionnaireTitle || '万户抖微',
        path: '/pages/index/index',
      }
    }
  },
  onShareAppMessage(){
    let shareData = this.getShareData()
    console.log('shareData:',shareData)
    return shareData
  }
  
})
